package main.controller;

import main.GlobalConfig;
import main.RequestHelper;
import main.TimeHelper;
import main.database.AccountHelper;
import main.database.BookCommentHelper;
import main.database.NotifyHelper;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Controller
public class ListBookCommentPageController {
    @GetMapping (value = "listbookcomment")
    public String listBookComment(HttpServletRequest request, ModelMap modelMap) {
        String uuid = RequestHelper.getUserUUIDFromRequest(request);
        boolean exist = AccountHelper.isExistFromUUID(uuid);
        boolean isAdmin = AccountHelper.isAdminFromUUID(uuid);

        List<String[]> contentList = BookCommentHelper.getAll();

        modelMap.put("year2year", TimeHelper.getFormattedYear2Year());
        modelMap.put("isLogin", exist);
        modelMap.put("isAdmin", isAdmin);

        long unread = NotifyHelper.countUnreadNotify(uuid);
        modelMap.put("unread", unread);
        modelMap.put("siteName", GlobalConfig.siteName);
        modelMap.put("contentList", contentList);

        return "listBookCommentPage";
    }
}
